package net.begincode.service;

import net.begincode.enums.StatusEnum;
import net.begincode.mapper.ServerMapper;
import net.begincode.model.Server;
import net.begincode.model.ServerExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by saber on 2017/9/23.
 */
@Service
public class ServerService {

    @Resource
    private ServerMapper serverMapper;


    /**
     * 查询所有服务
     * @return list 服务
     */
    public List<Server> listServer(){
        ServerExample serverExample = new ServerExample();
        ServerExample.Criteria criteria = serverExample.createCriteria();
        criteria.andIdIsNotNull();
        //criteria.andStatusEqualTo(Integer.parseInt(StatusEnum.NO_DEL_FLAG.getCode()));
        return serverMapper.selectByExample(serverExample);
    }

    /**
     * 查询所有未删除服务

     * @return list 服务
     */
    public List<Server> listServerUnDel(){
        ServerExample serverExample = new ServerExample();
        ServerExample.Criteria criteria = serverExample.createCriteria();
        //criteria.andIdIsNotNull();
        criteria.andStatusEqualTo(Integer.parseInt(StatusEnum.NO_DEL_FLAG.getCode()));
        return serverMapper.selectByExample(serverExample);
    }

    /**
     * 修改服务
     * @param server
     * @param serverId
     * @return Integer
     */
    public Integer updateServer(Server server ,Integer serverId){
        ServerExample serverExample = new ServerExample();
        ServerExample.Criteria criteria = serverExample.createCriteria();
        criteria.andIdEqualTo(serverId);
        return serverMapper.updateByExample(server,serverExample);
    }

    /**
     * 新增服务
     * @param server
     * @return Integer
     */
    public Integer insertServer(Server server){
        return serverMapper.insertSelective(server);
    }

    /**
     * 删除服务
     * @param serverId
     * @return Integer
     */
    public Integer deleteServer(Integer serverId){
        return serverMapper.deleteByPrimaryKey(serverId);
    }
}
